import PureTeamMembers from '../components/team-members';
import { getFetchStatus } from 'actions/util';
import * as DevTeamAction from 'actions/dev-team';
import * as ReactRedux from 'react-redux';

const mapStateToProps = (state, ownProps) => {
  const teamId = ownProps.teamId;
  return {
    loginUser: state.loginUser,
    isTeamLeader: state.loginUser.hasRole('DEV_TEAM_LEADER', teamId),
    memberAddFetching: getFetchStatus(state, DevTeamAction.addMembers)
  };
};

const mapDispatchToProps = (dispatch, ownProps) => {
  const teamId = ownProps.teamId;
  return {
    onSetLeader: (userId, enable) => {
      return dispatch(DevTeamAction.setLeader(teamId, userId, enable));
    },
    onRemoveMember: (userId) => {
      return dispatch(DevTeamAction.removeMember(teamId, userId));
    },
    onAddMembers: (userIds) => {
      return dispatch(DevTeamAction.addMembers(teamId, userIds));
    }
  };
};

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(PureTeamMembers);
